package com.example.demo.model.custom;

import com.baidu.bas.annotation.fun.DataProxy;
import com.example.demo.model.Account;

/**
 * @author liuzhenchuan@foxmail.com
 * @date 2020/12/29
 */
public class AccountDataProxy implements DataProxy<Account> {
    @Override
    public void beforeAdd(Account account) {
        setConf(account);
    }

    private void setConf(Account account) {
        if(account.getConfig()!=null){
            if(account.getName()!=null){
                account.getConfig().setName(account.getName());
            }
            if(account.getType()!=null){
                account.getConfig().setType(account.getType());
            }else{
                account.setType(account.getConfig().getType());
            }
        }
    }

    @Override
    public void beforeUpdate(Account account) {
        setConf(account);
    }
}
